package a;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

@WebServlet("/ServletRequestDemo6")
public class ServletRequestDemo6 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        //1.获取一个参数  一个name对应一个value
        String username = request.getParameter("username");
        System.out.println(username);
        //2.获取参数，一个name对应多个value值
        String[] hobbys = request.getParameterValues("hobby");
        System.out.println(Arrays.toString(hobbys));
        //3.获取所有参数，讲参数封装成map集合
        Map<String,String[]> map = request.getParameterMap();
        map.entrySet().forEach(entry ->{
            String mapKey = entry.getKey();
            String[] mapValue = entry.getValue();
            System.out.println(mapKey + "：" + Arrays.toString(mapValue));
                }
        );
    }
}
